Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Subarray Sum Equals K (medium)
Problem Statement
Given an array nums containing n integers and integer k, return the total number of subarrays having sum equal to k.
A subarray is defined as a contiguous non-empty sequence of the array elements.
Examples
Example 1:
- Input:
nums = [1, 2, 3], k = 3 - Expected Output:
2 - Justification: There are two subarrays that sum to 3:
[1, 2]and[3].
Example 2:
- Input:
nums = [10, 2, -2, -20, 10], k = -10 - Expected Output:
3 - Justification: Three subarrays sum up to -10:
[10, 2, -2, -20],[2, -2, -20, 10], and[-20, 10].
Example 3:
- Input:
nums = [5, 1, 2, -3, 4, -2], k = 3 - Expected Output:
2 - Justification: There are two subarrays that sum to 3:
[2, -3, 4], and[1, 2].
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Max Consecutive Ones III
Solution: Subarray Sum Equals K
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself